﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NangLuongTieuDiemDTO.DTO;
using NangLuongTieuDiemDAO.DAO;

namespace NangLuongTieuDiemBUS.BUS
{
    public class SoGioNangBUS
    {
        #region "[Insert]"
        public int Insert(SoGioNangDTO _obj)
        {
            int IDResult = -1;
            try
            {
                IDResult = SoGioNangDAO.Insert(_obj);
            }
            catch (Exception ex)
            {
                InSert_LoiHeThong("Insert", ex);
            }
            return IDResult;
        }
        #endregion

        #region "[Delete]"
        public bool Delete(int _ID)
        {
            bool isSuccess = false;
            try
            {
                isSuccess = SoGioNangDAO.Delete(_ID);
            }
            catch (Exception ex)
            {
                InSert_LoiHeThong("Delete", ex);
            }
            return isSuccess;
        }
        #endregion

        #region "[Update]"
        public bool Update(SoGioNangDTO _obj)
        {
            bool isSuccess = false;
            try
            {
                isSuccess = SoGioNangDAO.Update(_obj);
            }
            catch (Exception ex)
            {
                InSert_LoiHeThong("Update", ex);
            }
            return isSuccess;
        }
        #endregion

        #region "[GetAll]"
        public List<SoGioNangDTO> GetAll()
        {
            List<SoGioNangDTO> listResult = new List<SoGioNangDTO> ();
            try
            {
                listResult = SoGioNangDAO.GetAll();
            }
            catch (Exception ex)
            {
                InSert_LoiHeThong("GetAll", ex);
            }
            return listResult;
        }
        #endregion

        #region "[SelectByPrimaryKey]"
        public SoGioNangDTO SelectByPrimaryKey(int _ID)
        {
            SoGioNangDTO objResult = null;
            try
            {
                objResult = SoGioNangDAO.SelectByPrimaryKey(_ID);
            }
            catch (Exception ex) 
            {
                InSert_LoiHeThong("SelectByPrimaryKey", ex);
            }
            return objResult;
        }
        #endregion

        #region "[Hàm insert lỗi hệ thống]"//1241302 Đoàn Phú An
        public void InSert_LoiHeThong(string TenHam, Exception ex)
        {
            LoiHeThongDTO lhtDto = new LoiHeThongDTO();
            lhtDto.TenLoi = ex.Message.ToString();
            lhtDto.NgayTao = DateTime.Now;
            lhtDto.TenHamBiLoi = "SoGioNangBUS_" + TenHam;
            lhtDto.SuaLoi = false;
            lhtDto.GhiChu = "";
            LoiHeThongDAO.Insert(lhtDto);
        }
        #endregion
    }
}
